<template>
	<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%" @selection-change="selectionChangeHandle">
		<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
		<el-table-column prop="id" label="主键" header-align="center" align="center" v-if="false"></el-table-column>

		<el-table-column prop="imgUrl" label="封面图片" header-align="center" align="center">
			<template #default="scope">
				<el-image :src="scope.row.imgUrl" style="width: 50px; height: 50px; border: 1px solid #d3d3d340">
					<template #error>
						<div class="image-slot">
							<!-- /*图片加载失败显示的内容*/ -->
							<img src="@/assets/R-C.jpg" />
						</div>
					</template>
				</el-image>
			</template>
		</el-table-column>
		<el-table-column prop="name" label="课程标题" header-align="center" align="center"></el-table-column>
		<el-table-column prop="coursTypeName" label="课程类型" header-align="center" align="center"></el-table-column>
		<el-table-column prop="typeName" label="课程分类" header-align="center" align="center"></el-table-column>
		<el-table-column prop="isAll" label="可见范围" header-align="center" align="center"></el-table-column>

		<el-table-column prop="timingDate" label="学习人数" header-align="center" align="center"></el-table-column>
		<el-table-column prop="timingDate" label="收藏量" header-align="center" align="center"></el-table-column>
		<el-table-column prop="timingDate" label="分享量" header-align="center" align="center"></el-table-column>

		<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
			<template #default="scope">
				<el-button v-auth="'module:course:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">编辑</el-button>
				<el-button v-auth="'module:course:delete'" type="primary" link @click="deleteBatchHandle(scope.row.id)">移除</el-button>
			</template>
		</el-table-column>
	</el-table>
	<el-pagination
		:current-page="state.page"
		:page-sizes="state.pageSizes"
		:page-size="state.limit"
		:total="state.total"
		layout="total, sizes, prev, pager, next, jumper"
		@size-change="sizeChangeHandle"
		@current-change="currentChangeHandle"
	>
	</el-pagination>

	<!-- 弹窗, 新增 / 修改 -->
	<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList" :coursTypeList="coursTypeList"></add-or-update>
</template>

<script setup lang="ts" name="ModelCourseIndex">
import { useCrud } from '@/hooks'
import { Ref, reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import AddOrUpdate from './add-or-update.vue'
import { findListByDictId } from '@/api/nb/business/dictionaries_subset'

const state: IHooksOptions = reactive({
	dataListUrl: '/nb/course/page',
	deleteUrl: '/nb/course/delete',
	queryForm: {}
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

const coursTypeList = ref()
const getDbList = (code: String, list: Ref) => {
	return findListByDictId({
		params: {
			code: code
		}
	}).then(res => {
		list.value = res.data
	})
}
getDbList('KeChengFenLei', coursTypeList)

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
